import { message } from 'antd'
export const reject = (res) => {
    if (res.status === 499) {
        message.error('请求超时,请检查网络', 3);
    } else {
        message.error(res.status + ': 请求失败,请检查服务器', 3);
    }
}
export const headImageError = (e) => {
    e.target.src = require('../style/images/portrait.png');
}

export const loading = (_this, flag) => {
    _this.setState({
        loading: flag
    })
}

export const formatTimestamp = (timestamp, type) => {
    let now = new Date(timestamp);
    let year = now.getFullYear();
    let month = now.getMonth() + 1;
    let day = now.getDate();
    let hour = now.getHours();
    let minute = now.getMinutes();
    let second = now.getSeconds();
    month = month < 10 ? "0" + month : month;
    day = day < 10 ? "0" + day : day;
    hour = hour < 10 ? "0" + hour : hour;
    minute = minute < 10 ? "0" + minute : minute;
    second = second < 10 ? "0" + second : second;
    if (type === 'y-m-d') {
        return year + "-" + month + "-" + day;
    }
    if (type === 'y-m-d h-m') {
        return year + "-" + month + "-" + day + " " + hour + ":" + minute;
    }
    return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}